package com.easy.controller;

import java.util.List;

import com.easy.entity.query.EmpQuery;
import com.easy.entity.po.Emp;
import com.easy.entity.vo.ResponseVO;
import com.easy.service.EmpService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 员工表 Controller
 */
@RestController("empController")
@RequestMapping("/emp")
public class EmpController extends ABaseController{

	@Resource
	private EmpService empService;
	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("/loadDataList")
	public ResponseVO loadDataList(EmpQuery query){
		return getSuccessResponseVO(empService.findListByPage(query));
	}

	/**
	 * 新增
	 */
	@RequestMapping("/add")
	public ResponseVO add(Emp bean) {
		empService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("/addBatch")
	public ResponseVO addBatch(@RequestBody List<Emp> listBean) {
		empService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增/修改
	 */
	@RequestMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Emp> listBean) {
		empService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@RequestMapping("/getEmpById")
	public ResponseVO getEmpById(Integer id) {
		return getSuccessResponseVO(empService.getEmpById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@RequestMapping("/updateEmpById")
	public ResponseVO updateEmpById(Emp bean,Integer id) {
		empService.updateEmpById(bean,id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("/deleteEmpById")
	public ResponseVO deleteEmpById(Integer id) {
		empService.deleteEmpById(id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Username查询对象
	 */
	@RequestMapping("/getEmpByUsername")
	public ResponseVO getEmpByUsername(String username) {
		return getSuccessResponseVO(empService.getEmpByUsername(username));
	}

	/**
	 * 根据Username修改对象
	 */
	@RequestMapping("/updateEmpByUsername")
	public ResponseVO updateEmpByUsername(Emp bean,String username) {
		empService.updateEmpByUsername(bean,username);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Username删除
	 */
	@RequestMapping("/deleteEmpByUsername")
	public ResponseVO deleteEmpByUsername(String username) {
		empService.deleteEmpByUsername(username);
		return getSuccessResponseVO(null);
	}
}